package com.cysion.study.ui.personal

import com.cysion.study.ktbox.base.BaseActivity
import com.cysion.study.ktbox.net.BaseResponseRx
import com.cysion.study.ktbox.net.ErrorHandler
import com.cysion.study.ktbox.utils.darkTextTheme
import com.cysion.other.color
import com.cysion.targetfun._subscribe
import com.cysion.study.uibox.dialog.Alert
import com.cysion.study.R
import com.cysion.study.constant.BUNDLE_KEY
import com.cysion.study.customview.java.SimpleData
import com.cysion.study.helper.UserCache
import com.cysion.study.net.ApiClient
import com.cysion.study.widget.ShowToast
import kotlinx.android.synthetic.main.activity_attent_leave.*


//托管请假-请假学生
class AttentLeaveActivity : BaseActivity() {

    var simpleDatas: MutableList<SimpleData.Students> = mutableListOf()
    override fun getLayoutId(): Int = R.layout.activity_attent_leave
    private var caid=""
    private var type=""
    override fun initView() {
        caid="1"
//        caid = intent.extras.getString("caid")
        darkTextTheme(color(R.color.white))
        //type1请假,2早走,3晚走,4未续费
        type = intent.getBundleExtra(BUNDLE_KEY).getString("type")
        if (type == "1") {
            tv_title.setText("请假学生")
        }else if (type == "2") {
            tv_title.setText("早走学生")
        }else if (type == "3") {
            tv_title.setText("晚走学生")
        }else if (type == "4") {
            tv_title.setText("续费学生")
        }
        iv_back.setOnClickListener {
            finish()
        }




        /*simpleAdaper.setOnItemClicks {position, entity ->
            //flag 1 签到
            sendSign(position,entity)
        }*/


    }

    //签到/点名
    private fun sendSign(position: Int, entity: SimpleData.Students) {
        Alert.loading(self)
        //点名类型 0.托管课程 1.市集课程
        ApiClient.api.rollCall(UserCache.token, "bean.id", "entity.sid", "1")
            .compose(BaseResponseRx.validateToMain())
            ._subscribe {
                _onNext {
                    Alert.close()
                    ShowToast("点名成功")
                    getDataList()
                }
                _onError {
                    Alert.close()
                    ShowToast(ErrorHandler.handle(it).errorMsg)
                }
            }
    }

    override fun initData() {
        super.initData()
//        getDataList()
    }

    lateinit var bean:SimpleData
    private fun getDataList() {
        //isSign 是否签到 -1.全部 0.已签到 1.未签到
        ApiClient.api.classesGetByClid(UserCache.token,caid,"-1")
            .compose(BaseResponseRx.validateToMain())
            ._subscribe {
                _onNext {
                    Alert.close()
                    bean = it
                    /*simpleDatas = it.students
                    simpleAdaper.setDatas(simpleDatas)
                    CLog.e("@@@="+simpleDatas.size)
                    simpleAdaper.notifyDataSetChanged()*/

                }
                _onError {
                    Alert.close()
                    ShowToast(ErrorHandler.handle(it).errorMsg)
                }
            }
    }
    override fun closeMvp() {
    }


}
